var fs = require('fs');
var path = require('path');
var DxfStruct = require('./DxfStruct2');
var DxfParser = require('../');

var DXF_FILE_PATH = path.join(__dirname, 'data', 'GZxingren.dxf');
var OUTPUT_FILE_NAME = "cad.json";

var fileStream = fs.createReadStream(DXF_FILE_PATH, { encoding: 'utf8' });
var parser = new DxfParser();
var layer_color = {}

parser.parseStream(fileStream, function (err, dxf) {
    if (err) return console.error(err.stack);
    //fs.writeFileSync(OUTPUT_FILE_NAME, JSON.stringify(dxf, null, 3));

    dxf.sys = { start: 0, points: [], dn: 300 }
    dxfstruct = new DxfStruct(dxf)

    var newLayer = {
        layer: ['JMD','DLSS','交叉口标注坐标高程','道路分析','Road','XRoad'],
        //layer: ['XRoad'],
        hatch: ['XRoad'],
        //blocks: ['XRoad'],
        text: {
            'JMD': '标识标注',
        },
        clayer: {
            'XRoad': {
                '16711680': 'DN300',
            }
        },
        // new: {
        //     'Road': 'DLSS'
        // },
        // lineType:{
        //     '管网': {
        //         'ACAD_ISO12W100': 'DN300',
        //         //'ByLayer': 'DN200',
        //         'JIS_08_15': 'DN150',
        //         'HIDDEN': 'DN100',
        //     }
        // },
        tlayers: {
            'JMD': { c: '12237498', b: false },
            'DLSS': { c: '11382189', b: false },
            '交叉口标注坐标高程': { c: '16711935', b: false },
            'Road': { c: '11382189', b: false },
            '道路分析': { c: '255', b: false },
            'XRoad': { c: '11382189', b: false },
            

            'DN100': { c: '2278314', b: true },
            'DN150': { c: '9543307', b: true },
            'DN200': { c: '24234', b: true },
            'DN250': { c: '2851357', b: true },
            'DN300': { c: '39129', b: true },
            'DN400': { c: '15119872', b: true },
            'DN600': { c: '12660276', b: true }
        },
        //'4321','2110','注记'
        merge: ['JMD','DLSS','交叉口标注坐标高程','Road','XRoad']
    }
    
    //fs.writeFileSync(OUTPUT_FILE_NAME, JSON.stringify(dxfstruct.dxf.entities));//entities,tables
    dxfstruct.setShowLayers(newLayer)
    dxfstruct.resetDxf('user')

    console.log('dxfstruct', dxfstruct.dxf.entities.length)
    fs.writeFileSync(OUTPUT_FILE_NAME, JSON.stringify(dxfstruct.dxf));

    
   
    //console.log(dxfstruct.getDxfStruct())
});